package org.flycloud.web.platform.web;

import java.util.List;

import org.flycloud.web.platform.api.IPlatformController;
import org.flycloud.web.platform.entity.Menu;
import org.flycloud.web.platform.sevice.IPlatformService;
import org.flycloud.web.sso.common.SessionCache;
import org.flycloud.web.sso.common.Token;
import org.flycloud.web.sso.common.UserSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.SessionAttribute;

@Controller
@ResponseBody
public class PlatformController implements IPlatformController {

	@Autowired
	private IPlatformService menuService;

	@Autowired
	private SessionCache sessions;

	public List<Menu> menuTree(@SessionAttribute(Token.TOKEN) String token) {
		UserSession us = sessions.getToken(token);
		List<Menu> menus = menuService.getMenuList(us);
		return menus;
	}

	public UserSession login(@RequestParam("username") String username, @RequestParam("password") String password) {
		UserSession us = menuService.login(username, password);
		return us;
	}

}
